layui.define([ 'form', 'laydate', 'table' ], function(exports) {
    var form = layui.form;
    var laydate = layui.laydate;
    var table = layui.table;
    var excelTable = null;
    var view ={
        init:function(){
            this.initTable();
            this.initSearchForm();
            this.initToolBar();
            window.dataReload = function(){
                Lib.doSearchForm($("#searchForm"),excelTable)
            }
        },
        initTable:function(){
            excelTable = table.render({
                elem : '#excelTable',
                height : Lib.getTableHeight(1),
                cellMinWidth: 100,
                method : 'post',
                url : Common.ctxPath + '/cms/excel/companyList.json' // 数据接口
                ,page : Lib.tablePage // 开启分页
                ,limit : 10,
                cols : [ [ // 表头
                    {
                        type : 'checkbox',
                        fixed:'left',
                    },
                {

                    field : 'name',
                        title : '姓名',
                    align: 'center',
                    width:"120"
                },
                {

                    field : 'enterpriseName',
                        title : '在职单位',
                    align: 'center',
                    width:"200"
                },
                {

                    field : 'businessMatters',
                        title : '业务事项',
                    align: 'center',
                    width:"500"
                },

                {

                    field : 'processUserName',
                        title : '初审人',
                    align: 'center',
                    width:"105"
                },
                {

                    field : 'reviewUserName',
                        title : '复审人',
                    align: 'center',
                    width:"105"
                }
        ] ]

        });

            table.on('checkbox(excelTable)', function(obj){
                var excel = obj.data;
                if(obj.checked){
                    //按钮逻辑Lib.buttonEnable()
                }else{

                }
            })
        },

        initSearchForm:function(){
            Lib.initSearchForm( $("#searchForm"),excelTable,form);
        },
        initToolBar:function(){
            toolbar = {
                add : function() { // 获取选中数据
                    var url = "/cms/excel/add.do";
                    Common.openDlg(url,"excel>新增");
                },
                edit : function() { // 获取选中数目
                    var data = Common.getOneFromTable(table,"excelTable");
                    if(data==null){
                        return ;
                    }
                    var url = "/cms/excel/edit.do?id="+data.id;
                    Common.openDlg(url,"excel >编辑");
                },
                detailsExportDocument : function() {
                    layui.use([ 'excelApi' ], function() {
                        var testApi = layui.excelApi
                        Common.openConfirm("确认要导出这些企业数据?", function() {
                            testApi.detailsExportDocument($("#searchForm"), function(fileId) {
                                Lib.download(fileId);
                            })
                        })
                    });
                },
                exportDocument : function() {
                    layui.use([ 'excelApi' ], function() {
                        var testApi = layui.excelApi
                        Common.openConfirm("确认要导出这些企业数据?", function() {
                            testApi.companyExportExcel($("#searchForm"), function(fileId) {
                                Lib.download(fileId);
                            })
                        })
                    });
                },
                del : function() {
                    layui.use(['del'], function(){
                        var delView = layui.del
                        delView.delBatch();
                    });
                }
        };
            $('.ext-toolbar').on('click', function() {
                var type = $(this).data('type');
                toolbar[type] ? toolbar[type].call(this) : '';
            });
        }
    }
    exports('companyIndex',view);

});